import { IsDefined, IsNotEmpty, IsString, Length } from "class-validator";
import { BaseEntity } from "@/common/BaseEntity";
import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from "typeorm";
import SysMenuEntity from "../menu/Entity";

@Entity({
  name: "sys_menu_permission",
  orderBy: { createTime: "DESC" }
})
export default class SysMenuPermissionEntity extends BaseEntity {
  @PrimaryGeneratedColumn()
  public id: number;

  @Length(1, 20)
  @IsString()
  @IsNotEmpty()
  @IsDefined()
  @Column({
    nullable: true
  })
  public value: string;

  @Length(1, 20)
  @IsString()
  @IsDefined()
  @Column({
    nullable: true
  })
  public label: string;

  @ManyToMany(() => SysMenuEntity, (menu) => menu.permission)
  menu: SysMenuEntity[];

  public static transform(plainObject: object): SysMenuPermissionEntity {
    return super.baseTransform(SysMenuPermissionEntity, plainObject);
  }
}